package cn.qyd.concurrentcollection;

import java.util.concurrent.PriorityBlockingQueue;

/**
 * @author 邱运铎
 * @date 2024-03-22 21:33
 */
public class PriorityBlockingQueueDemo {
    static class Task implements Comparable<Task> {
        private String name;
        private Integer priority;

        public Task(String name, Integer priority) {
            this.name = name;
            this.priority = priority;
        }
        @Override
        public int compareTo(Task other) {
            return Integer.compare(other.priority,this.priority);
        }

        public String getName() {
            return this.name;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        PriorityBlockingQueue<Task> queue = new PriorityBlockingQueue<>();
        queue.put(new Task("High priority Thread",100));
        queue.put(new Task("Low priority Thread",10));
        queue.put(new Task("Medium priority thread",50));
        while (!queue.isEmpty()) {
            System.out.println(queue.take().getName());
        }
    }
}
